/**
 * 
 */
package com.aceitunaproject.server.translator;

import java.util.LinkedList;
import java.util.List;

import com.aceitunaproject.server.AceitunaContext;
import com.aceitunaproject.server.unit.UnitManager;
import com.aceitunaproject.shared.gamelement.Unit;
import com.aceitunaproject.shared.playerdata.PlayerData;

/**
 * @author Federico Bergstein
 * 
 */
public class UnitTranslator {

	/**
	 * Translates a server side UnitEntity to a shared Unit
	 * @param server side UnitEntity
	 * @return shared Unit
	 */
	public static List<Unit> ListToShared(LinkedList<Long> unitIDs) {
		
		UnitManager unitManager = AceitunaContext.getUnitManager();
		
		List<Unit> retList = new LinkedList<Unit>();
		
		for (Long unitID : unitIDs) {

			retList.add(toShared(unitManager.getUnit(unitID)));

		}
		
		return retList;
	}
	
	/**
	 * 
	 * Translates a list of Server side UnitEntity objects to a List of Shared Unit objects
	 * 
	 * @param List of Server side UnitEntity objects
	 * @return List of Shared Unit Objects
	 */
	public static Unit toShared(com.aceitunaproject.server.entity.unit.Unit from)
	{
	Unit to = new Unit();
	
	to.setId(from.getId());

	to.setName(from.getName());
	to.setTimeUnits(from.getTimeUnits());
	to.setPlayer(new PlayerData());
	to.getPlayer().setName(from.getOwner().getName());
	to.setPositionX(from.getCurrentPosition().x);
	to.setPositionY(from.getCurrentPosition().y);
	to.setPersons(from.getPersons());
	return to;


	}
}
